import 'dart:async';

import 'package:flutter/material.dart';
import 'package:music_app/theme/app_colors.dart';

class FakeSearchBar extends StatefulWidget {
  final List<String> hints;
  final VoidCallback onTap;
  final VoidCallback onScan;

  const FakeSearchBar({
    super.key,
    required this.hints,
    required this.onTap,
    required this.onScan,
  });

  @override
  State<FakeSearchBar> createState() => _FakeSearchBarState();
}

class _FakeSearchBarState extends State<FakeSearchBar> {
  int _currentHintIndex = 0;
  late Timer _timer;

  @override
  void initState() {
    super.initState();
    _timer = Timer.periodic(const Duration(seconds: 2), (timer) {
      setState(() {
        _currentHintIndex = (_currentHintIndex + 1) % widget.hints.length;
      });
    });
  }

  @override
  void dispose() {
    _timer.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: widget.onTap,
      child: Container(
        height: 38,
        padding: const EdgeInsets.only(left: 12, right: 12),
        decoration: BoxDecoration(
          color: AppColors.twobg,
          borderRadius: BorderRadius.circular(20),
        ),
        child: Row(
          children: [
            const Icon(
              Icons.search,
              color: AppColors.searchTextColor,
              size: 20,
            ),
            const SizedBox(
              width: 12,
            ),
            Expanded(
              child: AnimatedSwitcher(
                duration: const Duration(milliseconds: 300),
                child: Align(
                  alignment: Alignment.centerLeft,
                  child: Text(
                    widget.hints[_currentHintIndex],
                    key: ValueKey(_currentHintIndex),
                    style: const TextStyle(
                      color: AppColors.searchTextColor,
                      fontSize: 12,
                    ),
                    overflow: TextOverflow.ellipsis,
                  ),
                ),
              ),
            ),
            // GestureDetector(
            //   onTap: widget.onScan,
            //   child: const Icon(
            //     Icons.qr_code_scanner,
            //     color: Colors.black,
            //     size: 18,
            //   ),
            // ),
          ],
        ),
      ),
    );
  }
}
